﻿using System;
using System.Collections.Generic;
using System.Text;

using ApplicationLibrary;
using ApplicationLibrary.SqlConnector;
using ApplicationLibrary.DBManager;

using Vintner.Database;

namespace Vintner.Database
{
    class RegisterModule : RegisterTable
    {
        protected override string Module()
        {
            return "Vintner";
        }

        protected override int CurrentVersion()
        {
            return 1;
        }

        public override int Code()
        {
            return 1;
        }

        public override Version DllVersion
        {
            get
            {
                return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            }
        }

		public override void RegisterCountersAndCodes(ref GlobalInfo globalInfo)
		{
			globalInfo.AddCounter(11, global::Vintner.Properties.Resources.CN_Customers);
			globalInfo.AddCounter(12, global::Vintner.Properties.Resources.CN_SalesInvoice);
		}
        protected override bool CreateDBTables()
        {
            SqlCreateTable newTable = new SqlCreateTable(SqlABConnection);


            #region VI_Items

            if (SearchTable(VI_Items.Name))
            {
                newTable.NewTable(VI_Items.Name);

                newTable.AddColumn(VI_Items.Item);
                newTable.AddColumn(VI_Items.Description);
                newTable.AddColumn(VI_Items.Size);
                newTable.AddColumn(VI_Items.Disabled);

                newTable.AddPrimaryKey(VI_Items.Item);

                newTable.Create();
            }
            #endregion
            #region VI_ItemsPrice

            if (SearchTable(VI_ItemsPrice.Name))
            {
                newTable.NewTable(VI_ItemsPrice.Name);

                newTable.AddColumn(VI_ItemsPrice.Item);
                newTable.AddColumn(VI_ItemsPrice.Category);
                newTable.AddColumn(VI_ItemsPrice.Price);
                newTable.AddColumn(VI_ItemsPrice.TaxCode);

                newTable.AddPrimaryKey(new Column[] { VI_ItemsPrice.Item, VI_ItemsPrice.Category });

                newTable.Create();
            }
            #endregion
            #region VI_ItemCustomerPrice

            if (SearchTable(VI_ItemCustomerPrice.Name))
            {
                newTable.NewTable(VI_ItemCustomerPrice.Name);

                newTable.AddColumn(VI_ItemCustomerPrice.Item);
                newTable.AddColumn(VI_ItemCustomerPrice.Customer);
                newTable.AddColumn(VI_ItemCustomerPrice.Category);
                newTable.AddColumn(VI_ItemCustomerPrice.Disabled);

                newTable.AddPrimaryKey(new Column[] { VI_ItemCustomerPrice.Item, VI_ItemCustomerPrice.Customer });

                newTable.Create();
            }
            #endregion
            #region VI_SaleInvoice
            if (SearchTable(VI_SaleInvoice.Name))
            {
                newTable.NewTable(VI_SaleInvoice.Name);

                newTable.AddColumn(VI_SaleInvoice.InvoiceNo);
                newTable.AddColumn(VI_SaleInvoice.Customer);
                newTable.AddColumn(VI_SaleInvoice.Date);
                newTable.AddColumn(VI_SaleInvoice.Payment);

                newTable.AddPrimaryKey(new Column[] { VI_SaleInvoice.InvoiceNo});

                newTable.Create();
            }
            #endregion

            return true;
        }

        protected override bool UpdateDBTables()
        {
            return true;
        }
    }
}
